# -*- coding: utf-8 -*-
# @Time    : 2020/6/15 3:00
# @Author  : dearMrYang
# @File    : restful.py
# @Software: PyCharm
from django.http import JsonResponse


class HttpCode(object):
    ok = 200
    params_error = 400
    unauth_error = 401
    method_error = 405
    server_error = 500


def _result(code, message, data, **kwargs):
    return__dict = {
        "code": code,
        "message": message,
        "data": data
    }
    if kwargs and isinstance(kwargs, dict) and kwargs.keys():
        return__dict.update(kwargs)
    return JsonResponse(return__dict)


def ok(code=HttpCode.ok, message="成功~~", data={}, **kwargs):
    return _result(code=code, message=message, data=data, **kwargs)


def params_error(code=HttpCode.params_error, message="参数错误~~", data={}, **kwargs):
    return _result(code=code, message=message, data=data, **kwargs)


def unauth_error(code=HttpCode.unauth_error, message="未授权~~", data={}, **kwargs):
    return _result(code=code, message=message, data=data, **kwargs)


def method_error(code=HttpCode.method_error, message="方法错误~~", data={}, **kwargs):
    return _result(code=code, message=message, data=data, **kwargs)


def server_error(code=HttpCode.server_error, message="服务器错误~~", data={}, **kwargs):
    return _result(code=code, message=message, data=data, **kwargs)
